<?php

function xpath_avg($nodes){
  $suma = 0;
  foreach($nodes as $node){
    $value = $node->nodeValue;
    $suma = $suma + $value;
  }
  if(count($nodes)==0) return NAN;
  return $suma / count($nodes);
}


function xpath_min($nodes){
  $min = null;
  foreach($nodes as $node){
    $value = $node->nodeValue;
    if(!isset($min)) $min = $value;
    if($value < $min) $min = $value;
  }
  if(count($nodes)==0) return NAN;
  return $min;
}

function xpath_max($nodes){
  $max = null;
  foreach($nodes as $node){
    $value = $node->nodeValue;
    if(!isset($max)) $max = $value;
    if($value > $max) $max = $value;
  }
  if(count($nodes)==0) return NAN;
  return $max;
}

function xpath_count_non_empty($nodes){
  $count = 0;
  foreach($nodes as $node){
    $value = $node->nodeValue;
   if(!empty($value)){
	$count= $count + 1;
    }    
  }
  if(count($nodes)==0) return NAN;
  return $count;
}


function xpath_power($a,$b){
  return pow($a,$b);
}


function xpath_random($a,$b){
// radom entre dos numeros
  return rand($a,$b);
}

function xpath_compare($a,$b){
  return strcmp($a,$b);
}

